//
//  ViewController.swift
//  1.4.Displaying Static Text with UILabel
//
//  Created by joker on 15/7/21.
//  Copyright (c) 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var label: UILabel!

    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        label = UILabel()
        label.backgroundColor = UIColor.clearColor()
        label.attributedText = attributedText()
        label.sizeToFit()
        label.center = CGPoint(x: view.center.x , y: 100)
        view.addSubview(label)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func attributedText() -> NSAttributedString {
        let string = "iOS SDK" as NSString
        let result = NSMutableAttributedString(string: string as String)
        
        let attributesForFirstWord = [
            NSFontAttributeName: UIFont.boldSystemFontOfSize(60),
            NSForegroundColorAttributeName: UIColor.redColor(),
            NSBackgroundColorAttributeName: UIColor.blackColor()
        ]
        let shadow = NSShadow()
        shadow.shadowColor = UIColor.darkGrayColor()
        shadow.shadowOffset = CGSize(width: 4, height: 4)
        
        let attributesForSecondWord = [
            NSFontAttributeName: UIFont.boldSystemFontOfSize(60),
            NSForegroundColorAttributeName: UIColor.whiteColor(),
            NSBackgroundColorAttributeName: UIColor.redColor(),
            NSShadowAttributeName: shadow
        ]
        
        result.setAttributes(attributesForFirstWord, range: string.rangeOfString("iOS"))
        result.setAttributes(attributesForSecondWord, range: string.rangeOfString("SDK"))
        
        return NSAttributedString(attributedString: result)
    }
    
        

}

